Skip to content

feat(codegen-ts): sync SQLite service transactions and D1 service option - #643

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-130-lane-ts-2-b8
Nov 22, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-130-lane-ts-2-b8

Conversation

@dmealing

@dmealing dmealing commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • runtime-ts service: on a sync SQLite driver (bun:sqlite, better-sqlite3), the service drives its own transaction with BEGIN IMMEDIATE, COMMIT and ROLLBACK, instead of Drizzle's transaction(), which committed at the first await. Transactions serialize per database handle. A caller-supplied transaction gets a savepoint, and a read outside a transaction waits for the one in flight. New export withWriteTransaction(db, fn) runs several operations atomically on any driver. The generated SQLite Db type accepts sync and async drivers again; the asyncOnly option of dbTypeBlock is removed.
  • codegen-ts service: new serviceFile({ interactiveTransactions: false }) option, also on the ejectable reference twin and in the generator registry, for stores that hold no transaction across application code (Cloudflare D1). The service opens no transaction, and it generates no Hooks/Events interfaces or deps slots. A package that declares a command fails generation with ERR_STORE_NO_INTERACTIVE_TX, naming the package, the command and the option. Queries still generate.
  • Docs and decisions: ADR-0066 §6 now orders @inputRef validation before the permission point, and states the cost: a caller the policy would refuse can see a 400 before a 403. ADR-0067 §4 describes the new option and the refusal. docs/features/business-rules.md, docs/ports/typescript.md and the CHANGELOG cover the sync SQLite behavior and the withWriteTransaction caveat: on a sync driver, an operation that is not passed the outer tx waits on the transaction it is inside and never runs.
Validation

Risk Assessment

✅ Low: The change meets every stated criterion: both ADR amendments, the sync-SQLite fix with a widened Db type, the no-transaction option with its refusal, and tests that exercise real drivers. No concrete failing sequence turned up, and the known deadlock on a sync driver is documented.

Testing

Minimal retry; see full result.

  • Live validation: ✅ go - 1 of 1 scenarios driven live against the product
Scenario Result Live Evidence
sync SQLite generated service: rollback, concurrency, reads ✅ pass live service-sqlite-drivers.log

Gate and scope

  • One gate run. Its document step found one miss, which it fixed: the service entry in meta gen --list did not list the new interactiveTransactions? option.
  • This is the first part of the TypeScript lane's L-TS-6: the store option for stores without interactive transactions, the sync SQLite fix, and the ADR-0066 §6 and ADR-0067 §4 amendments. Finishing the Fastify transport (projections, reports, TPH, M:N and write-through through the service) and the Hono transport follow as separate PRs.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 1 of 1 scenarios driven live against the product
Scenario Result Live Evidence
sync SQLite generated service: rollback, concurrency, reads ✅ pass live service-sqlite-drivers.log
  • scripts/ci-local.sh --affected --strict-toolchains
  • bun test packages/runtime-ts/test/service-sync-sqlite.test.ts
  • bun test packages/integration-tests/test/service-sqlite-drivers.test.ts
  • bun test packages/codegen-ts/test/service-file.test.ts
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ⚠️ server/typescript/packages/codegen-ts/src/generator-registry.ts:305 - Generator catalog options string for service omits the new interactiveTransactions? option. generator-registry.ts line 305 still reads options: "filter?, runtimeImport?, target?". It should list interactiveTransactions?. This is a code string shown by meta gen --list, not a doc, so the doc-only rule kept it out of this phase.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

… interactiveTransactions: false for D1

The generated service committed at its first await on a sync SQLite driver (bun:sqlite,
better-sqlite3), so a refusal answered 409 over a row that stayed. The runtime now drives
those drivers' transaction with BEGIN IMMEDIATE/COMMIT/ROLLBACK, serialized per handle, and
the sqlite Db type accepts a sync driver again. serviceFile({ interactiveTransactions: false })
generates a service with no transaction, hooks or event hook for D1, and refuses a declared
command with ERR_STORE_NO_INTERACTIVE_TX. ADR-0067 section 4 says so.
@dmealing
dmealing merged commit 962459c into main Nov 22, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-130-lane-ts-2-b8 branch November 22, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant